package com.backend.exception;

import com.backend.common.ErrorCode;

/**
 * 抛出异常工具类
 * 当执行失败的时候，直接进入此处
 * 就是进一步对businessException封装
 */
public class ThrowUtils {

    /**
     * 条件成立，便抛出异常
     * @param condition 条件成立
     * @param runtimeException 异常
     */
    public static void throwIf(boolean condition, RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }

    public static void throwIf(boolean condition, ErrorCode errorCode) {
        // BusinessException继承RuntimeException
        throwIf(condition, new BusinessException(errorCode));
    }

    public static void throwIf(boolean condition, ErrorCode errorCode, String message) {
        throwIf(condition, new BusinessException(errorCode, message));
    }

}

